package com.gcb.controller.user;


import com.gcb.common.core.domain.PageResult;
import com.gcb.common.core.domain.R;
import com.gcb.domain.dto.GcbUserQueryDTO;
import com.gcb.domain.dto.GcbUserSaveDTO;
import com.gcb.domain.vo.GcbUserVO;
import com.gcb.service.IGcbUserService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 工船宝用户信息Controller
 */
@RestController
@RequestMapping("/user")
public class GcbUserController {

    @Autowired
    private IGcbUserService gcbUserService;

    /**
     * 001.查询工船宝用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('gcb:user:list')")
    @PostMapping("/page")
    public PageResult list(@RequestBody GcbUserQueryDTO dto) {
        PageHelper.startPage(dto.getPageNum(), dto.getPageSize());
        List<GcbUserVO> list = gcbUserService.selectGcbUserList(dto);
        return PageResult.ok(list);
    }

    /**
     * 002.批量禁用 - 恢复
     */
    @PreAuthorize("@ss.hasPermi('gcb:user:updateStatus')")
    @PostMapping("/edit/status/batch")
    public R<Void> updateStatus(@RequestBody GcbUserSaveDTO dto) {
        gcbUserService.updateStatus(dto);
        return R.ok();
    }

    /**
     * 004.获取工船宝用户信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('gcb:user:query')")
    @GetMapping(value = "/detail")
    public R<GcbUserVO> detail(@RequestParam Long id) {
        return R.ok(gcbUserService.getDetail(id));
    }

    @GetMapping("/edit/mobile")
    public R<Void> changeMobile(@RequestParam Long userId,@RequestParam String mobile) {
        gcbUserService.updateMobileByUserId(userId, mobile);
        return R.ok();
    }

}
